define([
  '../common/ReminderPanel',
  './CalcDistance',
  './CalcAngle',
  './CalcArea'
], function (
  ReminderPanel,
  CalcDistance,
  CalcAngle,
  CalcArea
) {

  let handler                                                                     //屏幕监听事件
  let reminder = new ReminderPanel();                                             //提醒框
  /*
    管理一组实体，
    在viewer下添加CustomDataSource可以对entities进行管理，
    且不影响viewer.entities下方法的使用
    */
  let measureEntities = new Cesium.CustomDataSource("measureEntities");

  viewer.dataSources.add(measureEntities);

  /*
    量测管理入口
  */
  return function () {

    //屏幕监听事件销毁与初始化
    $('#measureModule').click(function () {
      viewer.scene.screenSpaceCameraController.enableRotate = true
      destroyAllPlot()
      destroyAllMeasure()
      handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
    })

    $('#measureDistance').click(function () {
      reminder.show('正在测量距离')
      new CalcDistance(viewer, handler, reminder, measureEntities)
    })

    $('#measureAngle').click(function () {
      reminder.show('正在测量角度')
      new CalcAngle(viewer, handler, reminder, measureEntities)

    })

    $('#measureArea').click(function () {
      reminder.show('正在测量面积')
      new CalcArea(viewer, handler, reminder, measureEntities)
    })

    //销毁量测实体
    $('#clearMeasureData').click(function () {
      reminder.show('清除量测')
      clearMeasureData()
    })

    //清除量测实体
    window.clearMeasureData = function () {
      measureEntities.entities.removeAll()
    }

    //全局清理量测handler
    window.destroyAllMeasure = function () {
      if (handler !== undefined) {
        if (!handler.isDestroyed()) {
          handler.destroy()
          console.log('destroy')
        }
      }
    }
  }

})